package com.weixing.mall.provider.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weixing.mall.base.constant.GlobalConstant;
import com.weixing.mall.provider.mapper.GoodsTransBillMapper;
import com.weixing.mall.provider.mapper.GoodsTransBillProductMapper;
import com.weixing.mall.provider.model.domain.Depot;
import com.weixing.mall.provider.model.domain.GoodsTransBill;
import com.weixing.mall.provider.model.domain.GoodsTransBillProduct;
import com.weixing.mall.provider.model.query.GoodsTransQuery;
import com.weixing.mall.provider.model.vo.GoodsTransBillProductVo;
import com.weixing.mall.provider.service.IGoodsTransBillProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName GoodsTransBillProductServiceImpl
 * @Description TODO <br/>
 * @Author gjq
 * @Modified By:
 * @Date 2019/10/29
 * @Version 1.0
 **/
/**
 * <p>
 * 仓库模块-调拨单货品表 服务实现类
 * </p>
 *
 * @author Small
 * @since 2019-11-15
 */
@Service
public class GoodsTransBillProductServiceImpl extends ServiceImpl<GoodsTransBillProductMapper, GoodsTransBillProduct> implements IGoodsTransBillProductService {

    @Autowired
    private GoodsTransBillProductMapper goodsTransBillProductMapper;
    @Autowired
    private GoodsTransBillMapper goodsTransBillMapper;
    @Autowired
    private DepotServiceImpl depotService;

    @Override
    public IPage<GoodsTransBillProductVo> getGoodsTransBillProductByGoodsTransId(Page page, Long goodsTransId, GoodsTransQuery goodsTransQuery) {
        Long depotId = null;
        GoodsTransBill bill=goodsTransBillMapper.selectById(goodsTransId);
        //查询ERP仓IDm
        Depot depot=depotService.getDepotByCode(GlobalConstant.DepotCode.ERP);
        if(ObjectUtil.isNotEmpty(depot)
                &&depot.getId().equals(bill.getOutputDepot())){
             //ERP仓不加查询过滤条件
        }else{
            depotId = bill.getOutputDepot();
        }
        return goodsTransBillProductMapper.getGoodsTransBillProductByGoodsTransId(page,goodsTransId,depotId,goodsTransQuery);
    }

    @Override
    public List<GoodsTransBillProductVo> getGoodsTransBillProductByGoodsTransId(Long goodsTransId,Long outputDepotId,GoodsTransQuery goodsTransQuery) {
        //查询ERP仓ID
        Depot depot=depotService.getDepotByCode(GlobalConstant.DepotCode.ERP);
        if(ObjectUtil.isNotEmpty(depot)
                &&depot.getId().equals(outputDepotId)){
            //ERP仓不加查询过滤条件
            outputDepotId = null;
        }
        return goodsTransBillProductMapper.getGoodsTransBillProductByGoodsTransId(goodsTransId,outputDepotId,goodsTransQuery);
    }
}
